package com.sefonsoft.dataanalysis.service.impl.stjj.mhwz;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;

import com.sefonsoft.dataanalysis.model.stjj.mhwz.StjjMhwzZxtsldxxBean;
import com.sefonsoft.dataanalysis.service.impl.BaseService;
import com.sefonsoft.dataanalysis.service.model.Datas;
import com.sefonsoft.dataanalysis.utils.Tools;

/**
 * 咨询投诉领导信箱Service
 */
@Service
public class StjjMhwzZxtsldxxBeanService extends BaseService<StjjMhwzZxtsldxxBean> {

	@Override
	public Datas<StjjMhwzZxtsldxxBean> dataAnalysisByHtml(Document doc) {
		StjjMhwzZxtsldxxBean stjjmhwzzxtsldxxbean = new StjjMhwzZxtsldxxBean();
		Elements  el = doc.select("ul[class='msglist'] tr");
		Map<String,Integer> map = new HashMap<String,Integer>(){
			private static final long serialVersionUID = 1L;
			{
				put("您的姓名", 1);
				put("联系地址", 2);
				put("电子邮件", 3);
				put("标题", 4);
				put("信访类别", 5);
				put("具体内容", 6);
				put("回复单位", 7);
				put("回复内容", 8);
			}
		};
		if (el == null) {
			return null;
		}
		el.forEach(e->{
			String key = e.select("td:eq(0)")==null?"":e.select("td:eq(0)").text();
			String value = e.select("td:eq(1)")==null?"":e.select("td:eq(1)").text();
			if(StringUtils.isNotBlank(key)) {
				switch (map.get(key.trim().replaceAll(" ",""))) {
				case 1:
					stjjmhwzzxtsldxxbean.setNdxm(value);
					break;
				case 2:
					stjjmhwzzxtsldxxbean.setLxdz(value);
					break;
				case 3:
					stjjmhwzzxtsldxxbean.setDzyj(value);
					break;
				case 4:
					stjjmhwzzxtsldxxbean.setBt(value);
					break;
				case 5:
					stjjmhwzzxtsldxxbean.setXflb(value);
					break;
				case 6:
					stjjmhwzzxtsldxxbean.setJtnr(value);
					break;
				case 7:
					stjjmhwzzxtsldxxbean.setHfdw(value);
					break;
				case 8:
					stjjmhwzzxtsldxxbean.setHfnr(value);
					break;
				default:
					break;
				}
			}
		});
		stjjmhwzzxtsldxxbean.setId(Tools.createUUID());
		return new Datas<StjjMhwzZxtsldxxBean>(stjjmhwzzxtsldxxbean);
	}

	@Override
	public Class<StjjMhwzZxtsldxxBean> getTClass() {
		return StjjMhwzZxtsldxxBean.class;
	}
	
	@Override
	public void generateMap(Map<String, Object> map) {
		//作查询条件组装
		
	}
	
	@Override
	public Datas<StjjMhwzZxtsldxxBean> dataAnalysisByJson(String jsonStr) {
		/**
		 * 做json特殊处理
		 */
		return null;
	}
	
	@Override
	public Type getSourceType() {
		return Type.HTML;
	}

	
}
